#include "Header\Header.h"
#include "Header\ViewController.h"

#if CURRENT_PLATFORM == WIN
__bool_ __cdecl UpdateView();
__bool_ __cdecl UpdateView()
{
	ViewController<VIEWCLASS>::GetInstance()->GetView()->Update();
	return ViewController<VIEWCLASS>::GetInstance()->GetView()->IsQuit();
}
#endif

int _tmain(int argc, _TCHAR* argv[])
{
	//identifying memory leaks
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

	if (!ViewController<VIEWCLASS>::GetInstance())
	{
		//Create Client View
		ViewController<VIEWCLASS>::GetInstance()->CreateView(960, 540, TEXT("Game Engine"), FALSE, ES_WINDOW_RGB | ES_WINDOW_DEPTH);
	}

#if CURRENT_PLATFORM == WIN
	Game::GetInstance()->RegisterViewUpdateFunc(UpdateView);
#endif
	if (Game::GetInstance()->Start() != 0)
	{
#if CURRENT_DBG_MODE == DBG_BASE
		Device::GetInstance()->LogEx("Game state: Start error\n");
#endif
		return -1;
	}
	Game::GetInstance()->Run(0);
	Game::DestroyInstance();
	ViewController<VIEWCLASS>::DestroyInstance();
	Device::DestroyInstance();
	return 0;
}